package com.arpa.wms.domain.enums;

import com.baomidou.mybatisplus.core.enums.IEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 盘点确认单状态 枚举类型
 * @author jinss
 * @date 2020-08-29 11:13:42
 **/
public enum CountingRegisterStatusEnum implements IEnum<String> {
    // 由于之前状态复用了盘点单的状态，为兼容原数据，所以状态值不是连续的
    /**
     * 盘点确认单状态
     */
    WAIT_COUNT("1", "待盘点"),
    WAIT_AUDIT("3", "已盘点"),
    ;

    /**
     * 值
     */
    private final String value;

    /**
     * 描述
     */
    private final String desc;

    CountingRegisterStatusEnum(final String value, final String desc) {
        this.value = value;
        this.desc = desc;
    }

    private static final Map<String, CountingRegisterStatusEnum> ENUM_MAP = new HashMap();

    static {
        CountingRegisterStatusEnum[] values = values();
        int length = values.length;
        for(int i = 0; i < length; i++){
            CountingRegisterStatusEnum value1 = values[i];
            ENUM_MAP.put(value1.getValue(), value1);
        }
    }

    /**
     * 根据值获取枚举对象
     * @param value
     * @return
     */
    public static CountingRegisterStatusEnum getEnumByValue(String value){
        return ENUM_MAP.get(value);
    }

    public static String translate(String value) {
        CountingRegisterStatusEnum item = ENUM_MAP.get(value);
        if (item != null) {
            return item.getDesc();
        }
        return null;
    }

    public static CountingRegisterStatusEnum getByValue(String value) {
        for (CountingRegisterStatusEnum item : values()) {
            if (item.getValue().equals(value)) {
                return item;
            }
        }
        return null;
    }

    @Override
    public String getValue() {
        return this.value;
    }

    @Override
    public String toString(){
        return this.desc;
    }

    public String getDesc() {
        return this.desc;
    }
}
